package com.tz.common.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.tz.common.constant.Configs;


/**
 * Shared preferences util
 * Created by Chris on 16/7/18.
 */
public class PreferencesUtils {

    private static SharedPreferences mPreferences;
    private static SharedPreferences.Editor mEditor;

    public static void initPreferences(Context context) {
        mPreferences = context.getSharedPreferences(Configs.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        mEditor = mPreferences.edit();
    }

    public static void putString(String key, String value) {
        mEditor.putString(key, value).commit();
    }

    public static String getString(String key, String defValue) {
        return mPreferences.getString(key, defValue);
    }

    public static void putBoolean(String key, boolean value) {
        mEditor.putBoolean(key, value).commit();
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return mPreferences.getBoolean(key, defValue);
    }

    public static void putInt(String key, int value) {
        mEditor.putInt(key, value).commit();
    }

    public static int getInt(String key, int defValue) {
        return mPreferences.getInt(key, defValue);
    }

    public static void clearPre() {
        mEditor.clear();
        mEditor.commit();
    }

}
